package com.task.sql.schedule.common;/**
 * @ClassName : ApiResult
 * @Description :
 * @Author : liudonghai
 * @Date: 2024-09-10 11:54
 */

/**
 * @ClassName : ApiResult
 * @Description :
 * @Author : liudonghai
 * @Date: 2024-09-10 11:54
 */

import com.task.sql.schedule.constant.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class ApiResult<T> {

    @ApiModelProperty(value = "响应码")
    private Integer code;

    @ApiModelProperty(value = "提示信息")
    private String msg;

    @ApiModelProperty(value = "数据集合")
    private T data;

    public ApiResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiResult<T> success(T data) {
        return new ApiResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), data);
    }

    public static <T> ApiResult<T> success() {
        return new ApiResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), null);
    }

    public static <T> ApiResult<T> error(int code, String msg) {
        return new ApiResult(code, msg, null);
    }

    public static <T> ApiResult<T> error() {
        return new ApiResult(ResultCode.SERVICE_INTERNAL_ERROR.getCode(), ResultCode.SERVICE_INTERNAL_ERROR.getMsg(), null);
    }

    public static <T> ApiResult<T> error(ResultCode messageCode) {
        return new ApiResult(messageCode.getCode(), messageCode.getMsg(), null);
    }
}
